<template>
  <div>
    <el-row>
      <el-col :span="24">
        <el-card>
          <div slot="header" class="clearfix" style="text-align: center">
            <span>健康信息上报</span>
          </div>
          <el-table :data="tableData" border style="width: 100%">
            <el-table-column prop="username" label="姓名"> </el-table-column>
            <el-table-column prop="classes" label="班级"> </el-table-column>
            <el-table-column prop="address" label="生源地"> </el-table-column>
          </el-table>
        </el-card>
        <el-divider></el-divider>

        <el-card v-if="show == false">
          <div slot="header" style="text-align: center">
            <span>今日检测情况</span>
          </div>
          <el-alert title="今日申请表提交成功" type="success" center show-icon>
          </el-alert>
          <el-table :data="tableData1" border style="width: 100%">
            <el-table-column prop="temperature" label="当前体温">
            </el-table-column>
            <el-table-column prop="hot" label="是否发热、咳嗽">
            </el-table-column>
            <el-table-column prop="fever" label="是否有去就诊">
            </el-table-column>
            <el-table-column prop="gohubei" label="是否去过高危地区">
            </el-table-column>
            <el-table-column prop="hubeiren" label="是否为高危地区人员">
            </el-table-column>
            <el-table-column prop="mask" label="是否接触过高危地区人员">
            </el-table-column>
            <el-table-column prop="leaveout" label="是否离开过学校">
            </el-table-column>
            <el-table-column prop="hesuan" label="是否做过核酸检测">
            </el-table-column>
            <el-table-column prop="masknum" label="口罩数量"> </el-table-column>
            <el-table-column prop="kills" label="杀毒用品是否充足">
            </el-table-column>
          </el-table>
        </el-card>

        <el-card v-else-if="show == true">
          <el-form ref="form" :model="form" label-width="150px">
            <el-form-item label="当前体温">
              <el-input
                v-model="form.temperature"
                style="width: 130px"
              ></el-input>
            </el-form-item>
            <el-form-item label="是否发热、咳嗽">
              <el-radio-group v-model="form.hot">
                <el-radio label="否"></el-radio>
                <el-radio label="是"></el-radio>
              </el-radio-group>
            </el-form-item>
            <!--  <el-form-item label="是否有去就诊">
              <el-radio-group v-model="form.radio2">
                <el-radio label="否"></el-radio>
                <el-radio label="是"></el-radio>
              </el-radio-group>
            </el-form-item> -->
            <el-form-item label="是否去过高危地区">
              <el-radio-group v-model="form.gohubei">
                <el-radio label="否"></el-radio>
                <el-radio label="是"></el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="是否为高危地区人员">
              <el-radio-group v-model="form.hubeiren">
                <el-radio label="否"></el-radio>
                <el-radio label="是"></el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="是否接触过高危地区人员">
              <el-radio-group v-model="form.fever">
                <el-radio label="否"></el-radio>
                <el-radio label="是"></el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="是否离开过学校">
              <el-radio-group v-model="form.leaveout">
                <el-radio label="否"></el-radio>
                <el-radio label="是"></el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="是否做过核酸检测">
              <el-radio-group v-model="form.hesuan">
                <el-radio label="否"></el-radio>
                <el-radio label="是"></el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="口罩是否充足">
              <el-radio-group v-model="form.mask">
                <el-radio label="否"></el-radio>
                <el-radio label="是"></el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="口罩数量">
              <el-input v-model="form.masknum" style="width: 130px"></el-input>
            </el-form-item>
            <el-form-item label="杀毒用品是否充足">
              <el-radio-group v-model="form.kills">
                <el-radio label="否"></el-radio>
                <el-radio label="是"></el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="open">提交</el-button>
            </el-form-item>
          </el-form>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  data () {
    return {
      show: true,
      tableData: [],
      tableData1: [],
      form: {
        temperature: '',
        hot: '',
        gohubei: '',
        hubeiren: '',
        fever: '',
        leaveout: '',
        hesuan: '',
        mask: '',
        masknum: '',
        kills: '',
      },
      class_id: ''
    }
  },
  created () {

    this.getUser()

    /*调用获取当天某用户报表并且决定是否允许填写*/
    this.getnowdatah()
  },
  methods: {
    /*获取当天某用户报表并且决定是否允许填写*/
    async getUser () {
      const { data } = await this.$Axios('users/getUserInfo')
      this.getClass(data.class_id)
      console.log(data);
      this.tableData.push(data)

    },
    /* 获取班级 */
    async getClass (class_id) {
      const { data: result } = await this.$Axios.get('admin/getClass')
      result.forEach(item => {
        if (item.c_id == class_id) {
          this.tableData[0].classes = item.classes
          return
        }
      });
    },
    /*获取今天填写得到报表 */
    async getnowdatah () {
      const { data: result } = await this.$Axios.get('student/getHealthNowDayByid')
      if (result.code) {
        this.show = false;
        this.tableData1.push(result.data[0])
      } else {
        this.show = true
      }
      console.log(result)

    },
    /* 提交报表 */
    async onSubmit () {
      if (!this.form.temperature ||
        !this.form.hot ||
        !this.form.gohubei ||
        !this.form.hubeiren ||
        !this.form.fever ||
        !this.form.leaveout ||
        !this.form.hesuan ||
        !this.form.masknum ||
        !this.form.mask ||
        !this.form.kills)
        this.open3("填报表不可留空")
      else {
        let reg = /^\d+(\.\d+)?$/
        let reg1 = /^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$/
        let tempBool = reg1.test(this.form.temperature)
        let mskBool = reg.test(this.form.masknum)
        if (!tempBool) this.open3("体温请输入数字")
        else {
          if (!mskBool) this.open3("口罩数量请用数字方式输入")
          else {
            const result = await this.$Axios.post('student/sethealth', this.form)
            console.log(result);
            this.$message({
              type: 'success',
              message: "提交成功"
            })
            if (result.code != 0) {
              this.getnowdatah()
            }
          }

        }
      }
    },
    /* 获取班级 */

    /**
     * 提交弹窗
     */
    open () {
      this.$confirm('提交健康报表, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.onSubmit()
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消提交'
        });
      });
    },
    open3 (v) {
      this.$message({
        message: v,
        type: 'warning'
      });
    },

  },
}
</script>

<style scoped lang="scss">
</style>
